import java.awt.Button;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;
import javax.swing.ButtonGroup;
import javax.swing.JRadioButton;

/**
 * 
 */

/**
 * @author 
 * Yannic Remmet			196983
 * Tobias Trabelsi			197112
 * Anna-Katharina Wickert	197122
 */
public class CircleSquareDrawer extends Frame implements ActionListener {

	private static final long serialVersionUID = 8812549740337983498L;
	
	Frame drawFrame;
	Frame buttons;
	CircleSquare drawF;
	Button exit;
	Button clear;
	Button draw;
	ButtonGroup cirSq;
	JRadioButton circle;
	JRadioButton square;
	ButtonGroup fillUnf;
	JRadioButton fill;
	JRadioButton unfill;
	
	
	

    public CircleSquareDrawer()  {
            super();
            drawFrame = new Frame("Draw Frame");
            drawFrame.setSize(500,500);
         
            drawF = new CircleSquare();
            drawF.setBackground(Color.white);
            
            drawFrame.add(drawF);
            drawFrame.setVisible(true);
            
            drawF.draw();
            
            buttons = new Frame("Menu");
            exit = new Button("Exit");
            clear = new Button("Clear");
            draw = new Button("Draw");
            
            buttons.setLayout(new FlowLayout());
            buttons.add(exit);
            buttons.add(clear);
            buttons.add(draw);

            
            exit.addActionListener(this);
            clear.addActionListener(this);
            draw.addActionListener(this);
            
            buttons.setVisible(true);
            
            circle = new JRadioButton("Circle");
            circle.addActionListener(this);
            circle.setActionCommand("cir");
            circle.setSelected(true);
            square = new JRadioButton("Sqaure");
            square.addActionListener(this);
            square.setActionCommand("sq");
            cirSq = new ButtonGroup();
            cirSq.add(circle);
            cirSq.add(square);
            
            
            fill = new JRadioButton("Fill");
            fill.addActionListener(this);
            fill.setActionCommand("fill");
            fill.setSelected(true);
            unfill = new JRadioButton("Unfill");
            unfill.addActionListener(this);
            unfill.setActionCommand("unfill");
            fillUnf = new ButtonGroup();
            fillUnf.add(fill);
            fillUnf.add(unfill);
            
           buttons.add(fill);
           buttons.add(unfill);
           buttons.add(square);
           buttons.add(circle);
           buttons.pack();
           
            
    }
    
    public void actionPerformed(ActionEvent e) {
		if (e.getActionCommand().equals("Exit")){
			System.exit(1);
		}
		if (e.getActionCommand().equals("Clear")){
			drawF.repaint();
		}
		if (e.getActionCommand().equals("Draw")){
			Random number = new Random();
	    	int r = number.nextInt(256); 
	    	int g = number.nextInt(256);
	    	int b = number.nextInt(256);
	    	int z = number.nextInt(501); // maximum is 500 px, size
	    	int x = number.nextInt(501);
	    	int y = number.nextInt(501);
	    
			if (cirSq.getSelection().getActionCommand().equals("cir")){
				if (fillUnf.getSelection().getActionCommand().equals("fill")){
					drawF.fillCircle(x, y, z, r, g, b);
				}
				else {
					drawF.drawCircle(x, y, z, r, g, b);
				}
			}
			else{
				if (fillUnf.getSelection().getActionCommand().equals("fill")){
					drawF.fillSquare(x, y, z, r, g, b);
				}
				else{
					drawF.drawSquare(x, y, z, r, g, b);
				}
					
				
			}
		}
		
	}

  
  
}
